use askama_axum::Template;
use serde::{Deserialize, Serialize};
use tower_sessions::Session;

// 管理员表单数据
#[derive(Deserialize, Serialize)]
pub struct AdminSession { 
    pub id: i64,
    pub username: String
}

impl AdminSession {
    async fn init(session: Session) -> Self {
        let default = AdminSession{
            id: 0,
            username:"admin".to_string()
        };

        let admin = session.get::<AdminSession>("admin").await;

        match admin {
            Ok(Some(data)) =>  data,
            Ok(None) => {
                // 用户未登录
                return default;
            }
            Err(_) => {
                // 错误
                return default;
            }
        }
    }
}

#[derive(Template)]
#[template(path = "backend/error.html")]
struct ErrorTemplate {
    msg: String
}

pub mod home_controller;
pub mod config_controller;
pub mod advert_position_controller;
pub mod advert_controller;
pub mod category_controller;
pub mod blog_controller;
pub mod taxon_controller;
pub mod product_controller;
pub mod collect_type_controller;
pub mod collect_controller;
pub mod upload_controller;
pub mod admin_controller;
pub mod auth_controller;